package com.chinaoly.baotou.core;

import com.chinaoly.frm.core.entity.ShiroUser;

/**
 * 存储请求中的用户
 *
 * @author xuyh
 * @date 2022/3/25
 */
public class UserLocal {

    private static final ThreadLocal<ShiroUser> USER = new ThreadLocal<>();

    private static final ThreadLocal<String> TOKEN = new ThreadLocal<>();

    public static ShiroUser get() {
        return USER.get();
    }

    public static String getToken() {
        return TOKEN.get();
    }

    public static void set(ShiroUser user, String token) {
        USER.set(user);
        TOKEN.set(token);
    }

    public static void clean() {
        if (USER.get() != null) {
            USER.remove();
        }
        if (TOKEN.get() != null) {
            TOKEN.remove();
        }
    }

}
